<?
	session_start();
	ob_start();
	//global $TRDF;
	if(empty($_SESSION['user_login'])){
		echo"
		<br><br><br><br><br>
		<div align=center style='font-family: verdana; font-size: 10px; color: red;'>
		 Maaf, Halaman ini tidak bisa diakses. <br>
		 <a href='../index.php'>Anda harus login terlebih dahulu.</a><br><br><BR>
		 <span style='color:black;'>Karyawan Dot Net</span>
		</div>
		";
		exit();
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Report:: Medical Bank</title>
<style type="text/css">
 body,table{
 	font-family:Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
 }
</style>
<link rel="stylesheet" type="text/css" href="../style/print.css" media="print" />

<style type="text/css">
 .white_text{
 	background-color:#FFFFFF;
	color:#000000;
 }
</style>
</head>
<?
   	include("../lib/config.php");
	$awal		= $HTTP_GET_VARS['awal'];
	// dd-mm-yyyy
	// 0123456789
	$d = substr($awal,0,2);
	$m = substr($awal,3,2);
	$y = substr($awal,6,4);
	
	$awal 		= $y."-".$m."-".$d;
	
	$akhir		= $HTTP_GET_VARS['akhir'];
	
	$dd = substr($akhir,0,2);
	$mm = substr($akhir,3,2);
	$yy = substr($akhir,6,4);
	
	$akhir 		= $yy."-".$mm."-".$dd;

	$division	= $HTTP_GET_VARS['division'];
	
	// cek hak akses untuk cabang
	$sad = mssql_query("SELECT nama_menu FROM VPrivUser A, VCabang B WHERE username='".$HTTP_SESSION_VARS['user_login']."' AND baca='1' AND A.nama_menu=B.Kode_Cabang",$conn);
	while($rad = mssql_fetch_array($sad)){
	// VARIABLE UNTUK CABANG
	$VAreaCode[] = $rad[0];
	}
	/////////////////////////////////
?>
<body>
<table width="100%" border="0">
 <tr>
  <td align="left" style="font-size:14px;"><b>KOPERASI KARYAWAN</b></td>
 </tr>
 <tr>
  <td align="left" style="font-size:14px;"><b>DATA TRANSFER RESTITUSI UANG KESEHATAN</b></td>
 </tr>
 <tr>
  <td><b>Periode: <?=$HTTP_GET_VARS['awal']?> - <?=$HTTP_GET_VARS['akhir']?></b></td>
 </tr>
 <tr>
  <td align="right">Tgl Cetak: <?=date("d/m/Y")?></td>
 </tr> 
 <tr>
  <td>
  <table width="100%" border="1" bordercolordark="#000000" bordercolorlight="black" style="border-collapse: collapse; background-color: white;">
   <tr class="headlist">
    <td>No.</td>
    <td>NIK</td>
    <td>Nama</td>
    <td>Divisi/Biro/Unit Kerja/Cabang</td>
    <td>No. Rekening</td>
    <td>Atas Nama</td>
    <td>Nama Bank</td>
    <td>Dibayar</td>
   </tr>
   <?
	// get data transfer bank
	$sqlx  = "SELECT ROW_NUMBER() OVER(ORDER BY A.NIK) AS No, SUM(jml_disetujui) jml_bayar, A.NIK FROM MedicalRestitusiDetail A, VLatestKarir B, vlevelcabang C WHERE A.tgl_bayar BETWEEN '$awal' AND '$akhir' AND A.status='A' AND A.NIK=B.NIK AND B.kode_so2=C.kode_so ";
	
	if($division != "ALL"){
	$sqlx .= " AND substring(B.kode_so2,1,7)='".substr($division,0,7)."' ";
	}
	
	$sqlx .= " AND C.AreaCode IN (";

	for($k=0;$k<count($VAreaCode);$k++){
		$sqlx .= "'$VAreaCode[$k]',";
	}

	$sqlx .= "'$VAreaCode[0]') ";		
	
	$sqlx .= "GROUP BY A.NIK";
	
	$sql2 = mssql_query($sqlx,$conn);
	
	// jumlah total yang dibayarkan pada periode yang dipilih
	$sqly = "SELECT SUM(jml_disetujui) total_bayar FROM MedicalRestitusiDetail A, VLatestKarir B, vlevelcabang C WHERE A.tgl_bayar BETWEEN '$awal' AND '$akhir' AND A.status='A' AND A.NIK=B.NIK and B.kode_so2=C.kode_so ";

	if($division != "ALL"){
	$sqly .= " AND substring(B.kode_so2,1,7)='".substr($division,0,7)."'";
	}
	
	$sqly .= " AND C.AreaCode IN (";

	for($k=0;$k<count($VAreaCode);$k++){
		$sqly .= "'$VAreaCode[$k]',";
	}

	$sqly .= "'$VAreaCode[0]') ";		
	
	$sqlbayar = mssql_query($sqly,$conn);
	$rowbayar = mssql_fetch_array($sqlbayar);
	while($row2 = mssql_fetch_array($sql2)){
   ?>
   <tr>
    <td align="right" valign="top"><?=$row2[No]?></td>
    <td valign="top"><?
    	// get nik, nama, divisi
		$sql3 = mssql_query("SELECT A.NIK,A.Nama,kode_so2,kode_so1 FROM VLatestKarir A, MedicalRestitusiDetail B WHERE A.NIK=B.NIK AND B.NIK='".$row2[NIK]."' ",$conn);
		$row3 = mssql_fetch_array($sql3);
		echo"$row3[NIK]";
	?></td>
    <td valign="top"><?=$row3[Nama]?></td>
    <?
	// biro/cabang
	if(!empty($row3[kode_so2])){
		$kodeso = $row3[kode_so2];
	  	$uk3 	= mssql_query("SELECT * FROM VLevelCabang WHERE substring(kode_so,1,7)='".substr($kodeso,0,7)."'",$conn);
		$rk3	= mssql_fetch_array($uk3);		
	}
	?>
    <td valign="top"><small><?=$rk3[uraian]?></small></td>
    <?
    // get no rekening
  	$urek 	= mssql_query("SELECT no_rek, nama_rek, NamaBank FROM medicalnorekening A, MstBank B WHERE A.IdBank=B.IdBank AND NIK='$row2[NIK]'",$conn);
	$rrek	= mssql_fetch_array($urek);	
	?>
    <td valign="top"><?=$rrek[no_rek]?></td>
    <td valign="top"><?=$rrek[nama_rek]?></td>
    <td valign="top"><small><?=$rrek[NamaBank]?></small></td>
    <td align="right" valign="top"><?=number_format($row2[jml_bayar])?></td>
   </tr>
   <?
   }
   ?>
   <tr class="white_text">
    <td colspan="7" align="right">Total:</td>
    <td align="right"><b><?=number_format($rowbayar[total_bayar])?></b></td>
   </tr>
  </table>
  </td>
 </tr>
 <tr>
  <td><br /><br />
   <table align="left" style="position:relative; left: 45px;">
    <tr>
     <td colspan="3">Jakarta, ___________________________</td>
    </tr>
    <tr height="200">
     <td valign="bottom">___________________________</td>
     <td width="200">&nbsp;</td>
     <td valign="bottom">___________________________</td>
    </tr>
    <tr>
     <td>Ketua</td>
     <td width="200">&nbsp;</td>
     <td>Bendahara</td>
    </tr>
   </table>
  <td>
 </tr>
</table>
<?
//*///
if($HTTP_GET_VARS['excel'] == "yes"){
	header("Content-type: application/vnd.ms-excel");
	header("Content-Disposition: attachment; filename=LaporanPengobatanTransferBank.xls");
	header("Pragma: no-cache");
	header("Expires: 0");
	}
else{

}
//	*/
?>
</body>
</html>
